﻿using Pdoxcl2Sharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace V3MainTool.Model
{
    /// <summary>
    /// 建筑类别
    /// </summary>
    public class BuildingGroupsFamily : IParadoxRead, IParadoxWrite
    {
        public IList<BuildingGroups> MyList { get; set; }
        public BuildingGroupsFamily()
        {
            MyList = new List<BuildingGroups>();
        }

        public void TokenCallback(ParadoxParser parser, string token)
        {
            BuildingGroups item = parser.Parse(new BuildingGroups());
            item.name = token;
            MyList.Add(item);
        }

        public void Write(ParadoxStreamWriter writer)
        {
            for (int i = 0; i < MyList.Count; i++)
            {
                writer.Write(MyList[i].name, MyList[i]);
            }
        }
    }
    public class BuildingGroups : IParadoxRead, IParadoxWrite
    {
        #region 转换
        public string nameStr
        {
            get
            {
                Dictionary<string, string> dic = LocalHelper.Buildings;
                if (dic.TryGetValue(name, out string val))
                {
                    return val;
                }
                return name;
            }
        }
        public string parentStr
        {
            get
            {
                Dictionary<string, string> dic = LocalHelper.Buildings;
                if (parent_group == null)
                {
                    return parent_group;
                }
                if (dic.TryGetValue(parent_group, out string val))
                {
                    return val;
                }
                return parent_group;
            }
        }
        public string land_usageStr
        {
            get
            {
                Dictionary<string, string> dic = LocalHelper.Interfaces;
                if (land_usage == null)
                {
                    return land_usage;
                }
                if (dic.TryGetValue(land_usage, out string val))
                {
                    return val;
                }
                return land_usage;
            }
        }
        #endregion
        public string name { get; set; }
        public string category { get; set; }
        public string always_possible { get; set; }
        public string economy_of_scale { get; set; }
        public int? cash_reserves_max { get; set; }
        public string parent_group { get; set; }
        public string lens { get; set; }
        public int? urbanization { get; set; }
        public int? infrastructure_usage_per_level { get; set; }
        public string default_building { get; set; }
        public string auto_place_buildings { get; set; }
        public string is_subsistence { get; set; }
        public string ignores_hiring_rate { get; set; }
        public string land_usage { get; set; }
        public string can_use_slaves { get; set; }
        public string capped_by_resources { get; set; }
        public string discoverable_resource { get; set; }
        public string depletable_resource { get; set; }
        public string pays_taxes { get; set; }
        public string fired_pops_become_radical { get; set; }
        public string is_government_funded { get; set; }
        public string created_by_trade_routes { get; set; }
        public string stateregion_max_level { get; set; }
        public string subsidized { get; set; }
        public string inheritable_construction { get; set; }
        public string is_military { get; set; }
        public Should_auto_expand should_auto_expand { get; set; }

        public void TokenCallback(ParadoxParser parser, string token)
        {
            switch (token)
            {
                case "category": category = parser.ReadString(); break;
                case "always_possible": always_possible = parser.ReadString(); break;
                case "economy_of_scale": economy_of_scale = parser.ReadString(); break;
                case "cash_reserves_max": cash_reserves_max = parser.ReadInt32(); break;
                case "parent_group": parent_group = parser.ReadString(); break;
                case "lens": lens = parser.ReadString(); break;
                case "urbanization": urbanization = parser.ReadInt32(); break;
                case "infrastructure_usage_per_level": infrastructure_usage_per_level = parser.ReadInt32(); break;
                case "default_building": default_building = parser.ReadString(); break;
                case "auto_place_buildings": auto_place_buildings = parser.ReadString(); break;
                case "is_subsistence": is_subsistence = parser.ReadString(); break;
                case "ignores_hiring_rate": ignores_hiring_rate = parser.ReadString(); break;
                case "land_usage": land_usage = parser.ReadString(); break;
                case "can_use_slaves": can_use_slaves = parser.ReadString(); break;
                case "capped_by_resources": capped_by_resources = parser.ReadString(); break;
                case "discoverable_resource": discoverable_resource = parser.ReadString(); break;
                case "depletable_resource": depletable_resource = parser.ReadString(); break;
                case "pays_taxes": pays_taxes = parser.ReadString(); break;
                case "fired_pops_become_radical": fired_pops_become_radical = parser.ReadString(); break;
                case "is_government_funded": is_government_funded = parser.ReadString(); break;
                case "created_by_trade_routes": created_by_trade_routes = parser.ReadString(); break;
                case "stateregion_max_level": stateregion_max_level = parser.ReadString(); break;
                case "subsidized": subsidized = parser.ReadString(); break;
                case "inheritable_construction": inheritable_construction = parser.ReadString(); break;
                case "is_military": is_military = parser.ReadString(); break;
                case "should_auto_expand": should_auto_expand = parser.Parse(new Should_auto_expand()); break;
                default:
                    Console.WriteLine("unknow BuildingGroups prop:  " + token);
                    break;
            }
        }

        public void Write(ParadoxStreamWriter writer)
        {
            if (category != null) writer.WriteLine("category", category);
            if (always_possible != null) writer.WriteLine("always_possible", always_possible);
            if (economy_of_scale != null) writer.WriteLine("economy_of_scale", economy_of_scale);
            if (cash_reserves_max != null) writer.WriteLine("cash_reserves_max", cash_reserves_max.Value);
            if (parent_group != null) writer.WriteLine("parent_group", parent_group);
            if (lens != null) writer.WriteLine("lens", lens);
            if (urbanization != null) writer.WriteLine("urbanization", urbanization.Value);
            if (infrastructure_usage_per_level != null) writer.WriteLine("infrastructure_usage_per_level", infrastructure_usage_per_level.Value);
            if (default_building != null) writer.WriteLine("default_building", default_building);
            if (auto_place_buildings != null) writer.WriteLine("auto_place_buildings", auto_place_buildings);
            if (is_subsistence != null) writer.WriteLine("is_subsistence", is_subsistence);
            if (ignores_hiring_rate != null) writer.WriteLine("ignores_hiring_rate", ignores_hiring_rate);
            if (land_usage != null) writer.WriteLine("land_usage", land_usage);
            if (can_use_slaves != null) writer.WriteLine("can_use_slaves", can_use_slaves);
            if (capped_by_resources != null) writer.WriteLine("capped_by_resources", capped_by_resources);
            if (discoverable_resource != null) writer.WriteLine("discoverable_resource", discoverable_resource);
            if (depletable_resource != null) writer.WriteLine("depletable_resource", depletable_resource);
            if (pays_taxes != null) writer.WriteLine("pays_taxes", pays_taxes);
            if (fired_pops_become_radical != null) writer.WriteLine("fired_pops_become_radical", fired_pops_become_radical);
            if (is_government_funded != null) writer.WriteLine("is_government_funded", is_government_funded);
            if (created_by_trade_routes != null) writer.WriteLine("created_by_trade_routes", created_by_trade_routes);
            if (stateregion_max_level != null) writer.WriteLine("stateregion_max_level", stateregion_max_level);
            if (subsidized != null) writer.WriteLine("subsidized", subsidized);
            if (inheritable_construction != null) writer.WriteLine("inheritable_construction", inheritable_construction);
            if (is_military != null) writer.WriteLine("is_military", is_military);
            if (should_auto_expand != null) writer.Write("should_auto_expand", should_auto_expand);
        }
    }
    public class Should_auto_expand : IParadoxRead, IParadoxWrite
    {
        public string default_auto_expand_rule { get; set; }

        public void TokenCallback(ParadoxParser parser, string token)
        {
            switch (token)
            {
                case "default_auto_expand_rule": default_auto_expand_rule = parser.ReadString(); break;
                default:
                    Console.WriteLine("unknow should_auto_expand prop:  " + token);
                    break;
            }
        }

        public void Write(ParadoxStreamWriter writer)
        {
            if (default_auto_expand_rule != null) writer.WriteLine("default_auto_expand_rule", default_auto_expand_rule);
        }
    }
}
